package com.hmall.cart.listener;

import com.hmall.cart.service.ICartService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public class CartClearListener {
    @Autowired
    private ICartService cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "cart.clear.queue"),
            exchange = @Exchange(name = "trade.topic",type = "topic"),
            key = "order.create"
    ))
    public void listenClearCart(Collection<Long> itemIds) {
//        转换器自动解析消息头
//        Long userId = message.getMessageProperties().getHeader("user-info");
//        UserContext.setUser(userId);
        cartService.removeByItemIds(itemIds);
//        UserContext.removeUser();
    }
}
